package com.hzy.alibaba.config.redisson;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * 基本配置
 */
public class DistributedLockSingleConfig {
    @Value("${redisson.url}")
    private String url;
    @Value("${redisson.password}")
    private String password;

    public DistributedLockSingleConfig() {
    }

    @Bean
    public Config config() {
        Config config = new Config();
        config.useSingleServer().setAddress(this.url).setPassword(this.password);
        return config;
    }

    @Bean
    public RedissonClient redissonClient() {
        return Redisson.create(this.config());
    }

    @Bean
    public RedissonLocker redissonDistributedLock() {
        return new RedissonLocker(this.redissonClient());
    }
}
